Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify math expression code (use unary kernel) #309

Merged
merged 1 commit into from
May 10, 2021

Conversation

Dandandan
Copy link
Contributor

Which issue does this PR close?

Closes #308

Rationale for this change

Simplifies code, probably is faster too. Also involves one cast less which causes more rounding errors.

What changes are included in this PR?

Use arity::unary function to simplify math expression code

Are there any user-facing changes?

No

@@ -631,7 +631,7 @@ async fn sqrt_f32_vs_f64() -> Result<()> {
// sqrt(f32)'s plan passes
let sql = "SELECT avg(sqrt(c11)) FROM aggregate_test_100";
let actual = execute(&mut ctx, sql).await;
let expected = vec![vec!["0.6584408485889435"]];
let expected = vec![vec!["0.6584407806396484"]];
Copy link
Contributor Author

@Dandandan Dandandan May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small diff, since we avoid as f64 now.

Some(array) => compute_op!(array, $FUNC, $TYPE),
Some(array) => {
let res: $TYPE =
arrow::compute::kernels::arity::unary(array, |x| x.$FUNC());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids creating intermediate Vec and uses the (efficient) unary kernel

Copy link
Member

@jorgecarleitao jorgecarleitao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. 👍

@Dandandan Dandandan merged commit 11634f3 into apache:master May 10, 2021
@alamb
Copy link
Contributor

alamb commented May 10, 2021

🎉

@houqp houqp added datafusion Changes in the datafusion crate performance Make DataFusion faster labels Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate performance Make DataFusion faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify math expressions
4 participants